
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"  isELIgnored ="false"%>

<%@include file="/WEB-INF/jsp/common/include.inc.jsp"%>

<%@page import="org.springframework.security.core.userdetails.*"%>
<%@page import="org.springframework.security.core.*"%>
<%@page import="org.springframework.security.web.*"%>
<%@page import="org.springframework.security.authentication.*"%>
<%@page import="cn.fastmc.web.captcha.BadCaptchaException"%>
<%@page import="org.springframework.security.web.authentication.session.SessionAuthenticationException"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>Admin Console Login</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="" name="description" />
<meta content="" name="author" />
<meta name="MobileOptimized" content="320">
<!-- BEGIN GLOBAL MANDATORY STYLES -->
<script type="text/javascript" src="<%=basePath%>resource/plugins/jquery/jquery.js"></script>
<script type="text/javascript" src="<%=basePath%>resource/plugins/backstretch/jquery.backstretch.min.js"></script>
<script type="text/javascript" src="<%=basePath%>resource/plugins/jquery-validation/dist/jquery.validate.min.js"></script>
<script type="text/javascript" src="<%=basePath%>resource/plugins/jquery-validation/localization/messages_zh.js"></script>


<link rel="stylesheet" type="text/css" href="<%=basePath%>resource/plugins/bootstrap/css/bootstrap.min.css">
		
<link rel="stylesheet" type="text/css" href="<%=basePath%>resource/plugins/fontAwesome/css/font-awesome.min.css">
<link href="<%=basePath%>resource/css/login.css " rel="stylesheet" type="text/css" />
<style type="text/css">
label.valid {
  width: 24px;
  height: 24px;
  background: url(assets/img/valid.png) center center no-repeat;
  display: inline-block;
  text-indent: -9999px;
}
label.error {
  font-weight: bold;
  color: red;
  padding: 2px 8px;
  margin-top: 2px;
}
</style>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="login">
	<!-- BEGIN LOGIN -->
	<div class="clearfix" style="padding: 50px">
		<div class="content" style="width: 100%; max-width: 800px">
			<div class="row-fluid">
				<div class="span12">
					<div class="row-fluid">
						<div class="span4">
							<!-- //<img alt="" src="<%=basePath%>/resources/images/logo.png"> -->
						</div>
						<div class="span8">
							<h2 style="color: #555555">
								<s:property value="%{systemTitle}" />
							</h2>
						</div>
					</div>
				</div>
			</div>
			<hr />
			<div class="row-fluid">
				<div class="span112">
					<!-- BEGIN LOGIN FORM -->

					<form id="login-form"  class="form-horizontal" action="<%=basePath%>j_spring_security_check" method="post">
					  <fieldset><legend  style="color: #666666">系统登录</legend>
						<%
						    Exception e = (Exception) session
											.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
									if (e != null) {
										org.slf4j.Logger logger = org.slf4j.LoggerFactory
												.getLogger("lab.s2jh.errors.login");
										if (logger.isDebugEnabled()) {
											logger.debug("login.exception", e);
										}
										String msg = "系统处理错误，请联系管理员";
										if (e instanceof UsernameNotFoundException
												|| (e.getCause() != null && e.getCause() instanceof UsernameNotFoundException)) {
											msg = "账号不存在,请重新输入!";
										} else if (e instanceof DisabledException
												|| (e.getCause() != null && e.getCause() instanceof DisabledException)) {
											msg = "账号已停用,请联系管理员!";
										} else if (e instanceof AccountExpiredException
												|| (e.getCause() != null && e.getCause() instanceof AccountExpiredException)) {
											msg = "账号已过期,请联系管理员!";
										} else if (e instanceof CredentialsExpiredException
												|| (e.getCause() != null && e.getCause() instanceof CredentialsExpiredException)) {
											msg = "密码已过期,请联系管理员!";
										} else if (e instanceof LockedException
												|| (e.getCause() != null && e.getCause() instanceof LockedException)) {
											msg = "账号已被锁定,请联系管理员!";
										} else if (e instanceof BadCaptchaException
												|| (e.getCause() != null && e.getCause() instanceof BadCaptchaException)) {
											msg = "验证码校验失败，请重试!";
										} else if (e instanceof BadCredentialsException) {
											msg = "登录信息错误,请重新输入!";
										} else if (e instanceof SessionAuthenticationException){
										    msg = "当前用户已经登录不能重复登录,请联系管理员!";
										}
										session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
						%>
						<div class="alert alert-danger">
							<button class="close" data-close="alert"></button>
							<span><%=msg%></span>
						</div>
						<%
						    }
						%>
                        
						<div class="control-group">
							<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
							<label class="control-label">登录账号</label>
							<div class="controls ">
							<div class="input-prepend input-icon">
								 <span class="add-on"><i class="icon-user"></i></span>
								<input type="text" autocomplete="off" placeholder="登录账号" name="j_username" value="${sessionScope['SPRING_SECURITY_LAST_USERNAME']}"/>
							</div>
				           </div>
						</div>
						<div class="control-group">
							<label class="control-label">登录密码</label>
							<div class="controls">
							  <div class="input-prepend input-icon">
								 <span class="add-on "><i class="icon-lock"></i></span> <input class="form-control" type="password" autocomplete="off" placeholder="登录密码" name="j_password" />
                               </div>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label">验证码</label>
							<div class="controls">
								<div class=" input-prepend input-icon">
				
								 <span class="add-on"><i class="icon-qrcode"></span></i> <input class="form-control captcha-text" type="text" autocomplete="off"
										placeholder="验证码...看不清可点击图片可刷新" name="j_captcha" />
								</div>
								<span class="input-group-btn" style="cursor: pointer;"> <img alt="验证码" name="j_captcha" height="34px"
									class="captcha-img" src="<%=basePath%>resource/img/captcha_placeholder.jpg" title="看不清？点击刷新" />
								</span>
							</div>
						</div>
						<div class="control-group">
                         <div class="controls">
							<!-- <label> <input type="checkbox" name="_spring_security_remember_me" checked="true" value="true" /> 
								记住我(两周内自动登录)-->
							</label>   <button type="submit" class="btn btn-primary">登录</button>
						  </div>
						</div>
						</fieldset>
					</form>
					<!-- END LOGIN FORM -->
				</div>
			</div>

			<!-- BEGIN COPYRIGHT -->
			<div class="row-fluid">
				<div class="span12">
					<div class="copyright pull-right">
						<span title="${buildVersion}|<%= request.getLocalAddr()  %>:<%=request.getLocalPort()%>]"
							style="display: inline-block; width: 200px">${buildVersion}</span> 2014 &copy;
						<%=request.getServerName()%>
					</div>
				</div>
			</div>
			<!-- END COPYRIGHT -->


	

		</div>
	</div>
	
	
	<script type="text/javascript">
        jQuery(document).ready(function() {

           
            //FormValidation.init();

            $('#login-form').find("input:first").focus();

            jQuery('body').on('click', '.captcha-img', function(e) {
                $(".captcha-img").each(function() {
                    $(this).attr('src', '<%=basePath%>resource/img/captcha_placeholder.jpg');
                })
                $(this).attr('src', '<%=basePath%>pub/jcaptcha.servlet?_=' + new Date().getTime());
                var $captchaText = $(this).closest(".form-group").find(".captcha-text");
                $captchaText.val("");
                $captchaText.focus();
                return false;
            });

            jQuery('body').on('focus', '.captcha-text', function(e) {

                var $captchaImg = $(this).closest(".controls").find(".captcha-img");
                if ($captchaImg.attr("src") ==  '<%=basePath%>resource/img/captcha_placeholder.jpg') {
                    $captchaImg.click();
                }
            });

            $('#login-form').validate({
                errorElement : 'span', //default input error message container
                errorClass : 'help-block', // default input error message class
                focusInvalid : false, // do not focus the last invalid input
                rules : {
                    j_username : {
                        required : true
                    },
                    j_password : {
                        required : true
                    },
                    j_captcha : {
                        required : true
                    }
                },

                messages : {
                    j_username : {
                        required : "请填写登录账号"
                    },
                    j_password : {
                        required : "请填写登录密码"
                    },
                    j_captcha : {
                        required : "请填写登录验证码"
                    }
                },
               errorElement: "span",
               highlight: function(element) {
					$(element).closest('.control-group').removeClass('success').addClass('error');
			   },
			   success: function(element) {
					$(element).closest('.control-group').removeClass('error').addClass('success');
				},
				errorPlacement: function (error, element) {
				   error.appendTo(element.parents(".controls:first"));
				},

                submitHandler : function(form) {
                    form.submit();
                }
            });
            var imageHV = 'h';
            if ($(window).height() > $(window).width()) {
                imageHV = 'v';
                //$(".content").removeClass('pull-left');
            }
           
            $.backstretch([ "<%=basePath%>resource/img/bg/bg01_" + imageHV + ".jpg", "<%=basePath%>resource/img/bg/bg02_" + imageHV + ".jpg" ], {
                fade : 1000,
                duration : 8000
            });

           
        });
    </script>
</body>
<!-- END BODY -->
</html>